﻿namespace Budgetsch.WP7.Model.Live
{
    using System;
    using System.Collections.Generic;
    using System.Net;

    using Budgetsch.WP7.Model.DataService;
    using Budgetsch.WP7.ViewModel;
    using Budgetsch.WP7.WP7DataService;

    using GalaSoft.MvvmLight.Ioc;

    public class SavingDataService:ISavingDataService
    {
        private readonly CookieContainerViewModel _cookieContainer;

        public SavingDataService(CookieContainerViewModel cookieContainer)
        {
            _cookieContainer = cookieContainer; 
        }

        public void GetSavings(Action<IEnumerable<Saving>, Exception> callback)
        {
            var client = new WP7DataServiceClient { CookieContainer = this._cookieContainer.CookieContainer };
            client.GetSavingsCompleted += (s, e) => callback(e.Result, e.Error);
            client.GetSavingsAsync();
        }
    }
}
